﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

using NUnit.Framework;

using Refix.Core.IO;

namespace Refix.Core.Tests
{
    [TestFixture]
    public class ProjectFileTest
    {
        private DirectoryInfo _solutionRootDirectory;

        [TestFixtureSetUp]
        public void TextFixtureSetUp()
        {
            var fileInfo = new FileInfo(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
            _solutionRootDirectory = fileInfo.Directory.Parent.Parent.Parent;
        }

        [Test]
        public void BuildOutputFolderReadCorrectly()
        {
            var solutionfile =
                new SolutionFile(Path.Combine(_solutionRootDirectory.FullName,
                                              "Refix.TestSolution\\Refix.TestSolution.sln"));
            var projectFile = solutionfile.CachedProjectFiles.First().Value;
            Assert.AreEqual("bin\\Debug\\", projectFile.GetBuildOutputFolder("Debug"));
            Assert.AreEqual("bin\\Release\\", projectFile.GetBuildOutputFolder("Release"));
        }

        [Test]
        public void EnvironmentVariablesInSolutionFileParseCorrectly()
        {
            Environment.SetEnvironmentVariable("refixdir", Path.Combine(_solutionRootDirectory.FullName, "Refix.TestSolution\\"));
            var solutionfile =
                new SolutionFile(Path.Combine(_solutionRootDirectory.FullName,
                                              "Refix.TestSolution\\Refix.TestSolutionWithEnvironmentVariables.sln"));
            var projectFile = solutionfile.CachedProjectFiles.First().Value;
            Assert.AreEqual("bin\\Debug\\", projectFile.GetBuildOutputFolder("Debug"));
            Assert.AreEqual("bin\\Release\\", projectFile.GetBuildOutputFolder("Release"));
        }
    }
}
